package com.fanshuai.websocket.net;

import org.springframework.web.reactive.socket.WebSocketSession;

import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

public class WebFluxChatManager {
    public static Map<String, WebSocketChannel> channelMap = new ConcurrentHashMap<>();
    private static Set<WebSocketChannel> channels = new HashSet<>();

    public static void initChannel(WebSocketChannel channel) {
        channels.add(channel);
    }
    public static void addChannel(WebSocketSession session, String uid) {
        for (WebSocketChannel channel : channels) {
            if (channel.getSession() == session) {
                channelMap.put(uid, channel);
            }
        }
    }

    public static void delChanel(String uid) {
        channelMap.remove(uid);
    }
}
